﻿using System;
using System.Windows.Automation;
using Microsoft.VisualStudio.TestTools.UITesting.WpfControls;

namespace CodedUITestExtensions
{
    /// <summary>
    /// Extensions for WpfControl.
    /// </summary>
    public static class WpfControlExtensions
    {
        /// <summary>
        /// Gets automation element of control.
        /// </summary>
        /// <param name="control">WpfControl.</param>
        /// <returns>AutomationElement.</returns>
        public static AutomationElement GetAutomationElement(this WpfControl control)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }
            return (control.NativeElement as AutomationElement);
        }

        /// <summary>
        /// Gets IsOffscreen property of WpfControl.
        /// </summary>
        /// <param name="control">WpfControl</param>
        /// <returns>IsOffscreen property.</returns>
        public static bool IsOffScreen(this WpfControl control)
        {
            if (control == null)
            {
                throw new ArgumentNullException("control");
            }
            return control.GetAutomationElement().Current.IsOffscreen;
        }
    }
}
